package com.leetcode;

/**
 * 905. 按奇偶排序数组
 * 双指针 + 一次遍历 + 额外数组空间
 *
 * @author fy
 * @date 2022/4/28 9:44
 */
public class Solution905_2 {

    public int[] sortArrayByParity(int[] nums) {
        int n = nums.length;
        int left = 0;
        int right = n - 1;
        int[] res = new int[n];
        for (int num : nums) {
            if (num % 2 == 0) {
                res[left++] = num;
            } else {
                res[right--] = num;
            }
        }
        return res;
    }

}
